<template>
	<view style="height: 100%;">
		<view class="display_flex_bet u-m-b-20 bgfff u-p-20">
			<view class="u-flex-1">
				<el-button type="primary" size="mini" @click="show1 = true" class="u-m-l-20" icon="el-icon-plus">
					新增资源
				</el-button>



				<el-radio-group v-model="params.status" size="mini" @change="getData()" style="margin-left: 20rpx;">
					<el-radio-button label="全部"></el-radio-button>
					<el-radio-button label="1">已上架</el-radio-button>
					<el-radio-button label="-1">未上架</el-radio-button>
				</el-radio-group>
			</view>

			<view class="display_flex u-flex-2 u-row-right">
				<el-input placeholder="请输入商品名称" v-model="params.searchText" @change="confirmSearch" class="u-m-l-20"
					size="mini" style="width: 400rpx;" />

				<el-switch v-model="params.isNice" active-text="精选内容" inactive-text="" class="u-m-l-20"
					@change="confirmSearch" />
			</view>
		</view>


		<view class="u-padding-20 bgfff" style="height: calc(100% - 140rpx);width: calc(100% - 40rpx);margin: 20rpx;">
			<el-table :data="dataList" style="width: 100%" stripe border size="mini" height="95%">
				<el-table-column type="index" width="50">
				</el-table-column>
				
				<el-table-column prop="subGoodIcons" label="图片" width="100" align="center">
					<template slot-scope="scope">
						<el-image style="width: 20px; height: 20px" :src="scope.row.subGoodIcons[0]+'/sf'"
							:preview-src-list="scope.row.subGoodIcons" />
					</template>
				</el-table-column>
				
				<el-table-column prop="goodsName" label="商品名">
				</el-table-column>
				<el-table-column prop="tags" label="标签">
				</el-table-column>
				
				<el-table-column prop="minPrice" label="最低价" >
				</el-table-column>
				<el-table-column prop="maxPrice" label="最高价" >
				</el-table-column>
				
				<el-table-column prop="statusDesc" label="审核状态" >
				</el-table-column>
				
				<el-table-column prop="productId" label="关联小店的Id">
				</el-table-column>
				
				<el-table-column prop="createdAt" label="创建日期">
				</el-table-column>
				<el-table-column fixed="right" label="操作" width="100">
					<template slot-scope="scope">
						<el-button @click="deleteThis(scope.row)" type="text" size="small">删除</el-button>
						<el-button type="text" size="small" @click="editThis(scope.row)">编辑</el-button>
						<!-- <el-button v-if="scope.row.status == " @click="deleteThis(scope.row)" type="text" size="small">删除</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<view class="u-text-right bgfff u-padding-20">
				<el-pagination @current-change="handleCurrentChange" small :current-page="params.pageNum"
					:page-sizes="[20, 40, 60,80,100]" :page-count="maxPage"
					layout="total, sizes, prev, pager, next, jumper" :total="maxCount">
				</el-pagination>
			</view>
		</view>

		<goodEdit v-if="show1" @save="show1 = false,chooseItem='',getData()" :detail="chooseItem"
			@close="show1 = false,chooseItem = ''" :typeDesc="params.typeDesc" />
	</view>
</template>

<script>
	import goodEdit from '@/components/goodEdit'
	let that
	export default {
		components: {
			goodEdit
		},
		data() {
			return {
				fileTypeOptions: [{
					value: "",
					label: "全部"
				},{
					value: "课件",
					label: "课件"
				}, {
					value: "课程",
					label: "课程"
				}, {
					value: "素材",
					label: "素材"
				}],

				show1: false,
				chooseItem: '',
				dataList: [],
				maxCount: 1,
				maxPage: 1,

				params: {
					pageSize: 20,
					pageNum: 1,
					fileType: '课件',
					searchText: '',
					isNice: false,
					status: '全部',
				}
			}
		},

		onLoad() {
			that = this
			that.getData()
		},

		methods: {
			deleteThis(item) {
				uni.showModal({
					content: "是否删除此条目",
					success(res) {
						if (res.confirm) {
							that.$http.Post("admin/good/remove", {
								objectId: item.objectId
							}, "加载中...").then(res => {
								that.getData()
							})
						}
					}
				})
			},

			confirmSearch() {
				that.dataList = []
				that.params.pageNum = 1
				that.getData()
			},

			editThis(item) {

				this.chooseItem = item
				this.show1 = true
			},

			handleCurrentChange(value) {
				that.params.pageNum = value
				that.getData()
			},

			getData() {
				this.$http.Post("admin/good/list", that.params, "加载中...").then(res => {
					for (let item of res.data) {
						item.typeId = item.TypeId
					}
					this.dataList = res.data
					that.maxCount = res.maxCount
					that.maxPage = res.maxPage
				})
			}
		}
	}
</script>

<style>

</style>
